﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Excellent
{
    public partial class TheeditorForm : Form
    {
        public TheeditorForm()
        {
            InitializeComponent();
        }

        private void TheeditorForm_Load(object sender, EventArgs e)
        {
            string sql = string.Format(@"select * from T_gacct  ");
            DataTable tb = DBHelper.GetDataSet(sql).Tables[0];
            DataRow dr = tb.Rows[0];
            cBgrade.ValueMember = "gradeid";
            cBgrade.DisplayMember = "grade";
            cBgrade.DataSource = tb;
        }

        private void bttsave_Click(object sender, EventArgs e)
        {
            string Studentid = this.tBStudentid.Text.Trim();//学号
            string password = (this.tBpassword.Text.Trim());//密码
            string password1 = this.tBconfirm.Text.Trim();//确认密码  
            string name = this.tBname.Text.Trim();//姓名        
            string grade = this.cBgrade.SelectedValue.ToString();//年级
            string thephone = this.tBThephone.Text.Trim();//电话
            string address = this.tBaddress.Text.Trim();//地址
            DateTime dateofbirth = Convert.ToDateTime(this.dTPborn.Text.Trim());//出生日期
            string email = this.tBEmail.Text.Trim();//邮箱
            string sex = string.Empty;      //获得用户输入的性别
            if (raBfemale.Checked)
            {
                sex = "女";
            }
            else
            {
                sex = "男";
            }
            if (Studentid != "" || password != "" || password1 != ""|| name!="")
            {
            }
            else
            {
                MessageBox.Show("不能为空", "用户提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                return;
            }
            if (password.Equals(password1))
            {

            }
            else
            {
                MessageBox.Show("两次输入的密码不一致!", "用户提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            }
            string sql1 = string.Format("insert into StudentUsers(Studentid,name,typeId," +
                "password,sex,gradeid,phone,address,dateofbirth,email)" +
       "values('{0}', '{1}', '1','{2}', '{3}', '{4}', '{5}','{6}', '{7}','{8}')",
       Studentid, name, password, sex, grade, thephone, address, dateofbirth, email);        
            bool s = DBHelper.ExecuteNonQuery(sql1);
            if (s )
            {
                MessageBox.Show("添加成功");
            }
            else { MessageBox.Show("添加失败"); }
        }
        private void bttempty_Click(object sender, EventArgs e)
        {
            //foreach (Control c in Controls) {
            //    if (c is TextBox) {
            //        c.Text = "";
            //    }
            this.tBStudentid.Text="";//学号
            this.tBpassword.Text = "";//密码
            this.tBconfirm.Text = "";//确认密码
            this.tBname.Text = "";//姓名        
            this.tBThephone.Text = "";//电话
            this.tBaddress.Text = "";//地址
            this.tBEmail.Text = "";//邮箱

        }
        
    }
}
